#!/bin/bash
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
sudo apt-get update
sudo apt-get install ros-melodic-desktop-full -y
sudo apt-get install ros-melodic-rqt* -y
sudo apt-get install python-rosdep -y

cPath=`pwd`
sudo mkdir -p /etc/ros/rosdep/sources.list.d
sudo rm -f /etc/ros/rosdep/sources.list.d/20-default.list
echo "yaml file://`pwd`/rosdistro/rosdep/osx-homebrew.yaml osx" |sudo tee -a /etc/ros/rosdep/sources.list.d/20-default.list
echo "yaml file://`pwd`/rosdistro/rosdep/base.yaml" |sudo tee -a /etc/ros/rosdep/sources.list.d/20-default.list
echo "yaml file://`pwd`/rosdistro/rosdep/python.yaml" |sudo tee -a /etc/ros/rosdep/sources.list.d/20-default.list
echo "yaml file://`pwd`/rosdistro/rosdep/ruby.yaml" |sudo tee -a /etc/ros/rosdep/sources.list.d/20-default.list
echo "gbpdistro file://`pwd`/rosdistro/releases/fuerte.yaml fuerte" |sudo tee -a /etc/ros/rosdep/sources.list.d/20-default.list
sudo rm -f sources_list.real.py
sudo sed "s#DEFAULT_SOURCES_LIST_URL_REAL#file:\/\/${cPath}\/rosdistro\/rosdep\/sources.list.d\/20-default.list#" sources_list.py >> sources_list.real.py
sudo cp sources_list.py /usr/lib/python2.7/dist-packages/rosdep2/sources_list.py

sudo rm -f rep3.real.py
sudo sed "s#REP3_TARGETS_URL_REAL_LOCATION#file:\/\/${cPath}\/rosdistro\/releases\/targets.yaml#" rep3.py >> rep3.real.py
sudo cp rep3.real.py /usr/lib/python2.7/dist-packages/rosdep2/rep3.py

sudo rm -f __init__.real.py
sudo sed "s#DEFAULT_INDEX_URL_REAL#file:\/\/${cPath}\/rosdistro/index-v4.yaml#" __init__.py >> __init__.real.py
sudo cp __init__.real.py /usr/lib/python2.7/dist-packages/rosdistro/__init__.py

rosdep update

grep "source /opt/ros/melodic/setup.bash" ~/.bashrc || echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install  -y python-rosinstall python-rosinstall-generator python-wstool build-essential
